<template>
	<view class="skubox" @click="closeSku">
		<view class="skubg" @click.stop>
			<view class="skugoods">
				<y-goodsitem styleType="row" :item="items" imgsize="80px" />
				<view class="closesku">
					<uni-icons type="closeempty" :size="18" @click="closeSku"></uni-icons>
				</view>
			</view>
			<view class="skubody" v-if="items.skuList.length>0">
				<view class="goodsinfo-sku">
					<view class="sku-title">
						{{$t('index.ys')}}
					</view>
					<view class="skulist">
						<view :class="skuId == item.id?'sku-item active':'sku-item'"
							v-for="(item,index) in items.skuList" :key="index" @click="changeSku(item)">
							{{item.text}}
						</view>
					</view>
				</view>
			</view>
			<view class="skubtn">
				<view class="goodsnum">
					<view class="jian" @click="jianNum">
						-
					</view>
					<input type="number" v-model="num">
					<view class="add" @click="addNum">
						+
					</view>
				</view>
				<view class="btn">
					<button @click="midBuyNow">{{$t('index.ljjz')}}</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				num: 1,
				skuId: 1
			}
		},
		props: {
			items: {
				typeof: Object,
				default () {
					return {}
				}
			}
		},
		methods: {
			changeSku(e) {
				this.skuId = e.id
			},
			midBuyNow() {
				this.$emit('midBuyNow', [this.items.id, this.num, this.skuId])
			},
			jianNum() {
				if (this.num > 1) {
					this.num--
				}
			},
			addNum() {
				this.num++
			},
			closeSku() {
				this.$emit('closeSku', false)
			}
		}
	}
</script>

<style lang="scss">
	.skubox {
		position: fixed;
		top: 0;
		left: 0;
		background: #00000080;
		width: 100%;
		height: 100vh;
		z-index: 999;

		.skubg {
			background: #fff;
			bottom: 0;
			width: 100%;
			position: absolute;
			border-top-left-radius: 15px;
			border-top-right-radius: 15px;
		}

		.skugoods {
			display: flex;
			padding: 10px;

			.closesku {
				width: 20px;
				height: 20px;
				margin-left: 5px;
				text-align: center;
				line-height: 20px;
			}
		}

		.skubtn {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 10px;
			border-top: 1px solid #ccc;

			.goodsnum {
				display: flex;
				align-items: center;
				width: 50%;

				.jian,
				.add {
					color: #ff5353;
					width: 40px;
					text-align: center;
					font-size: 22px;
					cursor: pointer;
				}

				input {
					text-align: center;
					flex: 1;
				}
			}

			.btn {
				width: 40%;

				button {
					background: #ff5353;
					color: #fff;
					font-size: 14px;
				}
			}
		}

		.sku .sku-title {
			color: #000;
			font-weight: 400;
			font-size: 14px;
			line-height: 1.5;
			padding-top: 16px;
		}

		.goodsinfo-sku {
			padding: 0 10px;
			margin-bottom: 10px;
		}

		.skulist {
			display: flex;
			flex-wrap: wrap;

			.sku-item {
				box-sizing: border-box;
				display: inline-block;
				font-size: 14px;
				line-height: 1.2;
				min-width: 46px;
				padding: 10px 12px;
				text-align: center;
				color: #000;
				border-radius: 5px;
				border: 1px solid #ccc;
				margin: 8px 8px 0 0;
				cursor: pointer;

				&:hover {
					border-color: #ff5353;
				}

				&.active {
					background: #ff5353;
					color: #fff;
					border-color: #ff5353;
				}
			}
		}
	}

	@media (min-width:768px) {
		.skubox {
			display: none;
		}
	}
</style>